#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>

void lc_rmdir(char *f)
{
	DIR *dir = opendir(f);
	struct dirent *a;
	struct stat buf;
	char f2[100];
	while (a = readdir(dir))
	{
		if(strcmp(a->d_name,".") == 0 || strcmp(a->d_name,"..") == 0 )
			continue;
		
		stat(a->d_name,&buf);
		if( S_ISREG(buf.st_mode) == 1 )
		{
			remove(a->d_name);
			continue;
		}
		if( S_ISDIR(buf.st_mode) == 1 )
		{				
			strcpy(f2,f);	
			strcat(f2,"/");
			strcat(f2,a->d_name);
			lc_rmdir(f2);
		}				
	}
	closedir(dir);
	rmdir(f);
	return ;
}

void main()
{
	lc_rmdir("./CCC");
}